package com.android.yummycookies;

import java.util.ArrayList;

import android.app.Activity;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.os.Message;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.android.yummycookies.asyncTask.LoadBitmapThread;
import com.android.yummycookies.asyncTask.LoadCookieTypesThread;
import com.android.yummycookies.asyncTask.ScaleBitmapThread;
import com.android.yummycookies.loader.SimpleThemeLoaderOld;
import com.android.yummycookies.model.theme.Theme;
import com.android.yummycookies.service.storer.imagesStorer.BitmapsStoreService;
import com.android.yummycookies.service.storer.imagesStorer.binder.BitmapsStoreBinder;
import com.android.yummycookies.types.CookieType;

public class MainActivity extends Activity implements OnClickListener {

	static String TAG = MainActivity.class.getName();

	private Button button;
	private Theme theme;
	
	private LinearLayout layout;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);

		ArrayList<CookieType> types = new ArrayList<CookieType>();
		types.add(CookieType.DONUT_COOKIE);
		types.add(CookieType.CHECKERBOARD_COOKIE);
		theme = new Theme(R.string.action_settings,
				R.drawable.checkeroard_cookie, types);

		button = (Button) findViewById(R.id.button);
		button.setOnClickListener(this);
		
		layout = (LinearLayout) findViewById(R.id.container);
		
		for (CookieType cookieType : types) {
			if(cookieType.getBitmap() != null){
				ImageView i = new ImageView(getBaseContext());
				i.setImageBitmap(cookieType.getBitmap());
				layout.addView(i);
			}
			
			if(cookieType.getDestructionBitmap() != null){
				ImageView i = new ImageView(getBaseContext());
				i.setImageBitmap(cookieType.getDestructionBitmap());
				layout.addView(i);
			}
		}
	}

	@Override
	public void onClick(View v) {
		Intent i = new Intent(this, ThemeLoadingActivity.class);
		
		
		i.putExtra(ThemeLoadingActivity.ACTIVITY_TO_START, new Intent(this, MainActivity.class));
		i.putExtra(ThemeLoadingActivity.THEME_TO_LOAD, theme);
		i.putExtra(ThemeLoadingActivity.HEIGHT_TO_SCALE, 20);
		i.putExtra(ThemeLoadingActivity.WIDTH_TO_SCALE, 20);
		
		startActivity(i);
		finish();

	}

}
